Howto: Antialias edges and lines


[ Follow Ups ] [ Post Followup ] [ Björn's 3D-World - Developer's Board ]

Posted by Chris Lundie from dialin9.eagle.ca (206.186.242.246)on March 12, 1998 at 18:26:42:

When I first tried antialiasing I was very frustrated. You can't just issue an antialiased line or edge command and expect it to work.

First of all here's the difference. When you antialias an edge, you are smoothing out the edge of an object you have already drawn. This is how they do it in VQuake. An antialiased line is different than an edge. It's actually just a regular line, with some alpha blending applied at the edges.

For an antialiased edge, first you must set the following state: (It's very
specific in the RRedline manual)

'cmdbuffer' is my command buffer, and 'display' is a pointer to the display buffers (front, back, Z). My two vertices are A and B. Their format is v_rgbxyz.

---begin---
// set up drawing state for antialiasing
VL_SetSrcBase(&cmdbuffer, V_GetBufferAddress(display->buffer_group, 1));
VL_SetSrcStride(&cmdbuffer, V_GetBufferStride(display->buffer_group, 1));
VL_SetUMask(&cmdbuffer, display->width-1);
VL_SetVMask(&cmdbuffer, display->height-1);
VL_SetUClamp(&cmdbuffer, V_UCLAMP_ENABLE);
VL_SetVClamp(&cmdbuffer, V_VCLAMP_ENABLE);
VL_SetSrcFunc(&cmdbuffer, V_SRCFUNC_REPLACE);
VL_SetSrcFilter(&cmdbuffer, V_SRCFILTER_BILINEAR);
VL_SetSrcColorNoPad(&cmdbuffer, V_SRCCOLORPAD_DISABLE);
VL_SetChromaKey(&cmdbuffer, V_CHROMAKEY_DISABLE);
VL_SetALUMode(&cmdbuffer, V_ALUMODE_SRC);
VL_SetYUV2RGB(&cmdbuffer, V_YUV2RGB_DISABLE);
VL_SetBlendEnable(&cmdbuffer, V_BLEND_DISABLE);
VL_SetTranspReject(&cmdbuffer, V_TRANSPREJECT_DISABLE);
VL_SetFogEnable(&cmdbuffer, V_FOG_DISABLE);
VL_SetPatEnable(&cmdbuffer, V_PAT_DISABLE);

// antialias the edge
VL_AAEdge(&cmdbuffer, V_FIFO_RGBXYZ, (v_u32 *)&A, (v_u32 *)&B);
---end---

After you antialias the edge you have to restore any states you changed at the start.

Now here's the code for lines:
---begin---
// set up state for line antialiasing

VL_SetBlendEnable(&cmdbuffer, V_BLEND_ENABLE);
VL_SetBlendSrcFunc(&cmdbuffer, V_BLENDSRCALPHA);
VL_SetBlendDstFunc(&cmdbuffer, V_BLENDSRCALPHAINV);

// draw line
VL_AALine(&cmdbuffer, V_FIFO_RGBXYZ, (v_u32 *)&A, (v_u32 *)&B);
---end---

It's a lot simpler than doing edges. Basically all it does is enable alpha
blending. Again make sure you restore state afterward.

Any questions, comments, etc. please followup. This stuff is kinda tricky, but it's definitely one of the best features of RRedline.

Chris Lundie



Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ Björn's 3D-World - Developer's Board ]